<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" href="../../css/swiper.min.css">
    <link rel="stylesheet" href="../../font/iconfont.css">
</head>
<body>
	<div class="fenlei-left" id="nav">
		<ul id="shangcheng_cateshu">
		<!--
			<li onclick="shaixuan(this,{$vo.id});" class="shangcheng_cateshu_li shangcheng_shu_fl_active">商品分离</li>
			<li onclick="shaixuan(this,{$vo.id});" class="shangcheng_cateshu_li">商品分类</li>
		-->
		</ul>
	</div>
	<div id="menu_con">
	<!-- 全部 -->
		<ul class="fenlei-right" id="fenleigoodslist">
		<!--
			<li class="jg-qujian" onclick="openGoodsinfo();">
				<img src="../../image/shuoguo1.png">
				<h2>水果</h2>
				<h2 class="aui-text-success">￥75.00</h2>
			</li>
			<li class="jg-qujian" onclick="openGoodsinfo();">
				<img src="../../image/shuoguo1.png">
				<h2>水果</h2>
				<h2 class="aui-text-success">￥75.00</h2>
			</li>
			<li class="jg-qujian" onclick="openGoodsinfo();">
				<img src="../../image/shuoguo1.png">
				<h2>水果</h2>
				<h2 class="aui-text-success">￥75.00</h2>
			</li>
			<li class="jg-qujian" onclick="openGoodsinfo();">
				<img src="../../image/shuoguo1.png">
				<h2>水果</h2>
				<h2 class="aui-text-success">￥75.00</h2>
			</li>
		-->
		</ul>
	</div>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script>
//变量声明
var db_key = 'user',db_user,myParam,nowpage=1, loadend=false, isloading=false,status=0;
var useParam={}; useParam.rtk = RSapi.myrtk;
//监听滚动高度，加载下一页
var scroll = new auiScroll({
    listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
    distance:10 //判断到达底部的距离，isToBottom为true
},function(ret){
    if (ret.isToBottom) {
        loadlist(1);//显示更多数据
    }
});
//页面初始化
apiready = function() {
	myParam = api.pageParam;
    //加载商品分类竖向展示
    loadcate('shangchengcateshu',useParam,RSapi.base+RSapi.shangchengCateshu,'shangcheng_cateshu',myParam.cate);
}
//筛选
function shaixuan(type){
	//改变筛选按钮样式
	var $shaixuan_dom = $api.domAll(".shangcheng_cateshu_li");
	for (var j = 0; j < $shaixuan_dom.length; j++) {
		$api.removeCls($shaixuan_dom[j], 'shangcheng_shu_fl_active');
	}
	$api.addCls($api.byId("goods_fenlei_shaixuan_"+type),'shangcheng_shu_fl_active');
	status = type;//筛选参数值改变
	nowpage=1;//页码重新等于1
	loadend=false;
//	api.toast({msg: type});
	loadlist(2);//重新加载数据
}
//加载分类
function loadcate(status,param,url,domid,type) {
	api.ajax({
		url: url,
		method: 'post',
		cache: false,
		timeout: 30,
		dataType: 'json',
		data: { values: param },
	}, function(ret, err){
		if(err){
			api.alert({msg: err.msg});
		}else {
			if (ret.status>0) {
				//成功了
				$api.html($api.byId(domid), ' ');
				$api.append($api.byId(domid),ret.info);
				shaixuan(type);//控制分类选中状态
				api.parseTapmode();
				eval('status_'+status+'=true;');
			}else {
				//失败了
				api.toast({msg: ret.info});
			}
		}
	});
}

//加载内容列表
function loadlist(flag) {
	if (loadend) {/*api.toast({msg:'1'});*/return;}
    //禁止重复加载
    if (isloading) {/*api.toast({msg:'2'});*/return;}
    else isloading = true;
    api.showProgress();//显示加载进度框
    $api.removeCls($api.byId("cd_loading"),'none');//显示加载中

    useParam.page = nowpage;
	useParam.rtk = RSapi.myrtk;
	useParam.cid = status;

	api.ajax({
		url: RSapi.base+RSapi.shangchenglist,
		method: 'post',
		cache: false,
		timeout: 30,
		dataType: 'json',
		data: { values: useParam },
	}, function(ret, err){
		if(err){
			//api.toast({msg: JSON.stringify(err)});
			api.alert({msg: err.msg});
		}else {
			if (ret.status==1) {
				//成功了
				nowpage++;//页数加一
				if(flag == 1){
					$api.append($api.byId('fenleigoodslist'),ret.info);
				}else if(flag == 2){
					$api.html($api.byId('fenleigoodslist'),ret.info);
				}
				// loadend = true;
				$api.addCls($api.byId('wudongtai_box'), 'none');//显示无动态框
				api.parseTapmode();
				eval('status_'+status+'=true;');
			}else if(ret.status==2){
				//没有内容
				$api.html($api.byId('fenleigoodslist'),'');
				loadend = true;
				$api.removeCls($api.byId('wudongtai_box'), 'none');//显示无动态框
				$api.html($api.byId('wudongtai_txt'), ret.info);//显示提示内容
			}else if(ret.status==3){
				//成功了, 但是已经加载完毕
				//$api.html($api.byId('fenleigoodslist'),'');
        loadend = true;
        api.toast({msg:ret.info});
			}else {
				//失败了
				api.toast({msg: ret.info});
			}
		}
//		$api.addCls($api.byId("cd_loading"),'none');//隐藏加载中
		isloading = false;//加载结束
	});
	api.hideProgress();
}
//打开产品
function openGoodsinfo(id,title){
    api.openWin({
        name: 'win_goodsinfo',
        url: '../win/goodsinfo_win.html',
        pageParam: {gid: id,pagetitle:title}
    });
}
</script>
</html>
